package net.bright.demo.controller;

import net.bright.demo.ext.annotation.ControllerMapping;
import net.bright.demo.interceptor.BlogInterceptor;
import net.bright.demo.model.Blog;
import net.bright.demo.validator.BlogValidator;

import com.jfinal.aop.Before;

/**
 * BlogController
 */
@Before(BlogInterceptor.class)
@ControllerMapping(value = "/blog", path = "/module/blog")
public class BlogController extends BaseController {
	public void index() {
		setAttr("blogPage", Blog.me.paginate(getParaToInt(0, 1), 10));
		this.setSessionAttr("name", "joelli");
		
		render("blog.html");
	}
	
	public void add() {
	}
	
	@Before(BlogValidator.class)
	public void save() {
		getModel(Blog.class).save();
		redirect("/blog");
	}
	
	public void edit() {
		setAttr("blog", Blog.me.findById(getParaToInt()));
	}
	
	@Before(BlogValidator.class)
	public void update() {
		getModel(Blog.class).update();
		redirect("/blog");
	}
	
	public void delete() {
		Blog.me.deleteById(getParaToInt());
		redirect("/blog");
	}
}


